package com.heima.test4;

import java.util.Random;

public class Role {
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }
    //定义一个方法用于攻击别人
    //思考谁攻击谁
    //Role r1=new Role();
    //Role r2=new Role();
    //r1.attack(r2);方法的调用者去攻击参数
    public void attack(Role role){
        //计算造成的伤害，随机的1~20点伤害
        Random r=new Random();
        int hurry =r.nextInt(20)+1;
        //剩余血量
        int remainBlood=role.getBlood()-hurry;
        //对剩余血量进行判断
        remainBlood=remainBlood<0?0:remainBlood;
        role.setBlood(remainBlood);

        //this表示方法的调用者
        System.out.println(this.getName()+"攻击了"+role.getName()+
                "一下"+"造成了"+hurry+"点伤害"+role.getName()+"还剩下"+remainBlood+"点血");
    }

}
